Finding the median value without sorting